<?php
/**
 * Created by PhpStorm.
 * User: 杜磊磊
 * Date: 2020/5/25
 * Time: 11:43
 */
namespace app\controller;

use app\BaseController;
use think\facade\Db;
use app\model\tables;

class Data extends BaseController
{
    public function index()
    {
//        $result = Db::table('tables')->where('id',2)->find();
        //通过容器的方式获取
        $result = app('db')->table('tables')->where('id',2)->find();
        dump($result);
    }

    public function abc()
    {
        //第一种打印sql
//        $result = Db::table('tables')->where('id',10)->fetchSql()->find();
//        dump($result);

        //第二种打印sql
        $result = Db::table('tables')->where('id',10)->find();
        echo Db::getLastSql();exit;
    }

    public function demo()
    {
        $data = [
            'title' => 'duleilei',
            'content' => '111',
            'create_time' => time(),
            'status' => 1,
            'category_id' => 10
        ];
        //新增逻辑
        $result = Db::table('tables')->insert($data);
        echo Db::getLastSql();
        dump($result);
    }

    public function model1()
    {
        $result = tables::find(1);
        dump($result->toArray());
    }

    public function model2()
    {
        $modelOjb = new Tables();
        $results = $modelOjb->where('category_id',3)
            ->limit(2)
            ->order('id','desc')
            ->select();
        foreach($results as $result){
            dump($result['content']);
            dump($result->status_text);// 例如输出“正常”
        }


    }
}